package com.explore.demo.mapper;

import com.explore.demo.pojo.Company;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.explore.demo.pojo.Recruitment;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author gaolainan
 * @since 2021-04-14
 */
public interface CompanyMapper extends BaseMapper<Company> {

    /**
     * 获得公司的类别
     * @param companyId 公司的id
     * @return
     */
    @Select("select category_name from category where id in (select category_id  from company_category where company_id = #{companyId})")
    List<String> getCategoryName(Integer companyId);

    /**
     * 查找当前公司发布的招聘信息
     * @param companyId 公司的id
     * @return
     */
    @Select("select count(*) from recruitment where company_id = #{companyId} and deleted = 0")
    Integer getNowRecruitmentNum(Integer companyId);

    /**
     * 根据类别拿到公司的信息
     * @param categoryName 类别的名称
     * @return
     */
    @Select("select * from company where id in (select company_id from company_category where category_id = (select id from category where category_name = #{categoryName}))")
    List<Company> getAllCompanyInfo(String categoryName);

    /**
     * 获得最受欢迎的的公司
     * @return
     */
    @Select("select * from company where id in (select company_id from (select company_id from row_view group by company_id order by sum(read_num) desc limit 8) as company_id)")
    List<Company> getTopCompany();

    /**
     * 获得最新的公司
     * @return
     */
    @Select("select * from company order by create_time desc limit 1")
    Company getNewCompany();

}
